package com.payment.common.utils.file;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import java.util.ResourceBundle;

public class FilePropertiesUtil {
    private static final Logger log = LoggerFactory.getLogger(FilePropertiesUtil.class);
	  /**
     * 
     * {读取项目中的properties配置文件}<br>
     * 返回的是ResourceBundle的对象
     * 
     * @param propertiesFilePath
     * @return
     */
    public static ResourceBundle readFromProject(String propertiesFilePath)
    {
        return ResourceBundle.getBundle(propertiesFilePath);
    }
 
    /**
     * 
     * {读取磁盘上的properties配置文件}<br>
     * 返回的市Properties的对象
     * @param propertiesFilePath
     * @return
     */
    public static Properties readFromSystemFile(String propertiesFilePath)
    {
        InputStream is = null;
        Properties properties = null;
        try
        {
            is = new FileInputStream(propertiesFilePath);
            properties = new Properties();
            properties.load(is);
 
        }
        catch (FileNotFoundException e)
        {
            log.info("没有找到文件");
            e.printStackTrace();
        }
        catch (IOException e)
        {
            log.info("读取properties文件失败");
            e.printStackTrace();
        }
        finally
        {
            if (is != null)
            {
                try
                {
                    is.close();
                }
                catch (IOException e)
                {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        }
        return properties;
    }
 
    /**
     * 
     * {主函数}
     * 
     * @param args
     */
    public static void main(String[] args)
    {
        //ResourceBundle resourceBundle = readFromProject("db1");

        String filePath = "D:" + File.separator +"config.properties";
        Properties properties = readFromSystemFile(filePath);
        String base = properties.getProperty("YX_bindMsgUrl");
        String step = properties.getProperty("YX_bindConfirmUrl");
        System.out.println(base + " " + step);
    }
}
